package com.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dao.UserDao;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.pojo.User;
import com.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class UserServiceImpl extends MPJBaseServiceImpl<UserDao,User> implements UserService {

    @Resource
    private UserDao userDao;

    @Override
    public List<User> getUserList() {
        List<User> userList = this.getUserList();


        List<User> userList1 = new ArrayList<>();
        return userList;
    }

    @Override
    public User SignIn(int id, String password) {
        User user = userDao.selectById(id);
        if(password.equals(user.getPassword())){
            return user;
        }
        return null;
    }
    /*
    * User user = userDao.selectById(id);
        User newUser = new User();
        if(password.equals(user.getPassword())){
            newUser = userDao.selectById(id);
        }
        return newUser;*/
    /*@Resource
    private UserDao userDao;

    @Override
    public List<User> getUserList() {
        List<User> userList = userDao.selectList(null);
        return userList;
    }

    @Override
    public boolean ExcelImport(String filePath) {
        List<User> list = new ArrayList<User>();
        ExcelReader excelReader = EasyExcel.read(filePath, User.class, new AnalysisEventListener<User>() {
            @Override
            public void invoke(User user, AnalysisContext analysisContext) {
                System.out.println("每次都会加载：" + user.toString());
                list.add(user);
            }
            @Override
            public void doAfterAllAnalysed(AnalysisContext analysisContext) {
                System.out.println("解析成功...");
            }
        }).build();
        ReadSheet build = EasyExcel.readSheet(0).build();
        excelReader.read(build);
        excelReader.finish();
        int count = list.size();
        int sum = 0;
        for (User user : list) {
            int i = userDao.addUser(user);
            sum++;
        }
        return count==sum;
    }*/
}
